<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 17-2-22
 * Time: 下午3:47
 */


//可变函数

//PHP 支持可变函数的概念。这意味着如果一个变量名后有圆括号，
//PHP 将寻找与变量的值同名的函数，并且尝试执行它。
//可变函数可以用来实现包括回调函数，函数表在内的一些用途。
//可变函数不能用于例如 echo，print，unset()，isset()，empty()，include，require
// 以及类似的语言结构。需要使用自己的包装函数来将这些结构用作可变函数。

function foo(){
    echo __FUNCTION__;
}
$foo = "foo";
$foo();

function foo2(...$a){
    print_r($a);
}

$foo = "foo2";
$foo(1,2,3,4);

class Student{

    public $userId;
    private $userName;

    public static $classRoom = "Num 1".PHP_EOL;
    function __construct($id,$name)
    {
        $this->userId = $id;
        $this->userName = $name;
    }

    public function get(){
        return $this->userId.PHP_EOL.$this->userName.PHP_EOL;
    }

    public static function get2(){
        return Student::$classRoom;
    }
    public static function classRoom(){
        return __METHOD__.Student::$classRoom;
    }

    public static function staticClass(){
        return __METHOD__;
    }

}
$get = "get";
$stu = new Student("000001","zing");
echo $stu->$get();
echo $stu->get();
echo Student::get2();

$classRoom = "classRoom";
echo Student::$classRoom;
echo Student::$classRoom();
echo Student::classRoom();


echo str_repeat("*",30);
echo PHP_EOL;
$sc = Student::staticClass();
echo $sc();


class One{
    public function one1(){
        echo __METHOD__.PHP_EOL;
    }
}
class Two{
    public function two2(){
        echo __METHOD__.PHP_EOL;
    }
}
class Three{
    public function three3(){
        echo __METHOD__.PHP_EOL;
    }
}

$calls = ['One' => 'one1','Two' => 'two2','Three' => 'three3'];

echo PHP_EOL;
foreach ($calls as $k => $v){
    (new $k)->$v();
}